package com.ruoyi.web.controller.admin;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

import com.alibaba.fastjson.JSON;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.vo.HospitalSubscribeOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.system.domain.HospitalSubscribeOrder;
import com.ruoyi.system.service.IHospitalSubscribeOrderService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2025-04-30
 */
@RestController
@RequestMapping("/admin/order")
public class HospitalSubscribeOrderAdminController extends BaseController
{
    @Autowired
    private IHospitalSubscribeOrderService hospitalSubscribeOrderService;


    /**
     * 查询订单关联的所有信息
     * @response {@link HospitalSubscribeOrderVo}
     */
    @GetMapping("/getOrderAllInfo")
    public TableDataInfo list(HospitalSubscribeOrder hospitalSubscribeOrder)
    {
        startPage();
        if (hospitalSubscribeOrder.getStatus() != null){
            ArrayList<Integer> statusList = new ArrayList<>();
            statusList.add(0);
            statusList.add(1);
            statusList.add(2);
            statusList.add(3);
            statusList.add(5);
            statusList.add(6);
            hospitalSubscribeOrder.setStatusList(statusList);
        }
        List<HospitalSubscribeOrderVo> list = hospitalSubscribeOrderService.getOrderAllInfo(hospitalSubscribeOrder);
        return getDataTable(list);
    }

    /**
     * 完成订单
     */
    @GetMapping("/completeOrder")
    public AjaxResult completeOrder(@RequestParam("orderId") Long orderId)
    {
        return success(hospitalSubscribeOrderService.completeOrder(orderId));
    }

    /**
     * 支付成功回调
     */
    @PostMapping("/paySuccessCallback")
    public String paySuccessCallback(HttpServletRequest request)
    {
        return JSON.toJSONString(hospitalSubscribeOrderService.paySuccessCallback(request));
    }

    /**
     * 订单申请退款
     */
    @GetMapping("/refundOrder")
    public AjaxResult refundOrderItem(@RequestParam("orderId") Long orderId)
    {
        return success(hospitalSubscribeOrderService.refundOrder(orderId));
    }

    /**
     * 退款成功回调
     */
    @PostMapping("/refundSuccessCallback")
    public String refundSuccessCallback(HttpServletRequest request)
    {
        return JSON.toJSONString(hospitalSubscribeOrderService.refundSuccessCallback(request));
    }

    /**
     * 上传检查项目图片
     */
    @PostMapping("/uploadingProjectPhotograph")
    public AjaxResult uploadingProjectPhotograph(@RequestBody HospitalSubscribeOrder hospitalSubscribeOrder)
    {
        return toAjax(hospitalSubscribeOrderService.updateHospitalSubscribeOrder(hospitalSubscribeOrder));
    }

    /**
     * 查询订单关联的所有信息
     * @response {@link HospitalSubscribeOrderVo}
     */
    @GetMapping("/getCompleteAllInfo")
    public TableDataInfo getCompleteAllInfo(HospitalSubscribeOrder hospitalSubscribeOrder)
    {
        startPage();
        ArrayList<Integer> statusList = new ArrayList<>();
        statusList.add(4);
        statusList.add(7);
        hospitalSubscribeOrder.setStatusList(statusList);
        List<HospitalSubscribeOrderVo> list = hospitalSubscribeOrderService.getOrderAllInfo(hospitalSubscribeOrder);
        return getDataTable(list);
    }

}
